package org.xx.armory.config.security;

import java.util.HashMap;
import java.util.Map;

import static org.xx.armory.commons.Validators.notBlank;
import static org.xx.armory.commons.Validators.notNull;

/**
 * 安全相关的配置项。
 */
public final class SecuritySection {
    private final Map<String, KeySection> keys;
    private AuthenticationSection authentication;

    public SecuritySection() {
        this.keys = new HashMap<>();
        this.authentication = new AuthenticationSection();
    }

    public AuthenticationSection getAuthentication() {
        return authentication;
    }

    public void setAuthentication(
            AuthenticationSection authentication
    ) {
        this.authentication = authentication;
    }

    public void addKey(
            KeySection item
    ) {
        notNull(item, "item");

        this.keys.putIfAbsent(item.getName(), item);
    }

    public KeySection getKey(
            String name
    ) {
        name = notBlank(name, "name").trim();

        return this.keys.getOrDefault(name, null);
    }
}
